$(function() {
	
	//选择文件按钮
	$("#bchoose").click(function() {
		$("#ichoose").click();　　
	});

	$("#ichoose").change(function() {
		var file = document.getElementById("ichoose").files[0];
		$("#choosedfile").val(file.name);
	});
	//上传按钮
	$("#bupload").click(function() {
		$("#current_path").val(PATH);

		var reader = new FileReader();
		var file = document.getElementById("ichoose").files[0];
		reader.onload = function() {
			text = (reader.result);
			var hash1 = CryptoJS.MD5(CryptoJS.enc.Latin1.parse(text)).toString();
			var hash2 = CryptoJS.SHA256(CryptoJS.enc.Latin1.parse(text)).toString();
			console.log(hash1)
			console.log(hash2)
			var PhysicsFileID = 0;
			var fileName = file.name;
			$.ajax({
				type: 'GET',
				url: "../api/checkmd5andhash",
				data: {
					"md5value": hash1,
					"hashvalue": hash2,
					"filesize": file.size

				},
				success: function(msg) {
					console.log(msg);
					if(msg.code == 1) {
						PhysicsFileID = msg.message;
						$.ajax({
							type: 'POST',
							url: "../api/uploadfilebyshare",
							data: {
								"uuid": PhysicsFileID,
								"current_path": PATH,
								"fileName": fileName
							},
							success: function() {
								mdui.snackbar({
									message: '您的文件已经秒传',
									buttonText: '返回',
									onClick: function() {
										location.reload();
									},
									onButtonClick: function() {
										location.reload();
									},
									onClose: function() {
										location.reload();
									}
								});
							},
							dataType: "JSON"
						});
					} else if(msg.code == 3) {
						mdui.snackbar({
							message: '当前的文件空间已满,开通会员或清理文件',
							buttonText: '返回',
							onClick: function() {
								location.reload();
							},
							onButtonClick: function() {
								location.reload();
							},
							onClose: function() {
								location.reload();
							}
						});
					} else if(msg.code == 0) {
						$("#uploadform").submit();

					} else {
						mdui.snackbar({
							message: '内部错误,请稍候',
							buttonText: '返回',
							onClick: function() {
								location.reload();
							},
							onButtonClick: function() {
								location.reload();
							},
							onClose: function() {
								location.reload();
							}
						});
					}
				},
				dataType: "JSON"
			});
		}
		reader.readAsBinaryString(document.getElementById("ichoose").files[0]);

	});
});